package com.ad.pet.app.main;

import android.app.Activity;

import com.ad.pet.api.ApiService;
import com.ad.pet.app.RxDisposable;
import com.ad.pet.common.data.http.AppSubscriber;
import com.ad.pet.common.structure.mvp.AbsBasePresenter;
import com.ad.pet.models.remote.CommList;
import com.ad.pet.models.remote.home.Cate;
import com.ad.pet.models.remote.home.Home;
import com.ad.pet.models.remote.home.NewUserBenfit;
import com.ad.pet.models.remote.home.Product_list;
import com.ad.pet.models.remote.home.VpPacket;

import java.util.List;

import javax.inject.Inject;

/**
 * Created by SEELE on 2018/3/23.
 */

public class HomePresenter  extends AbsBasePresenter implements HomeContract.Presenter{

    private ApiService mApiService;
    private HomeContract.View mView;

    private Activity mActivity;

    private RxDisposable mRxDisposable;

    @Inject
    public HomePresenter(ApiService apiService,
                               Activity activity, RxDisposable rxDisposable) {
        mApiService = apiService;
        mActivity = activity;
        mRxDisposable = rxDisposable;
    }

    @Override
    public void onDestroy() {
        if (mRxDisposable != null)
        mRxDisposable.clear();
        if (mActivity != null) mActivity = null;
        mView = null;
    }

    @Override
    public void onCreate(HomeContract.View view) {
        this.mView = view;
    }





    @Override
    public void getPicList(String type,String longtitu,String latitude) {
        mRxDisposable.add(mApiService.getPicList(type,longtitu,latitude)
                .subscribe(new AppSubscriber<Home>(mView) {
                    @Override
                    public void next(Home list) {
                        mView.getPicListSuccess(list);
                    }
                }));
    }







    @Override
    public void getFeatureDataColumn() {
        mRxDisposable.add(mApiService.getFreeZoomsColumn()
                .subscribe(new AppSubscriber<Cate>(mView) {
                    @Override
                    public void next(Cate list) {
                        mView.getFeatureDataColumnSuccess(list);
                    }
                }));
    }

    @Override
    public void getVpPackets() {
        mRxDisposable.add(mApiService.getVpPackets()
                .subscribe(new AppSubscriber<CommList<List< VpPacket>>>(mView) {
                    @Override
                    public void next(CommList<List<VpPacket>> list) {

                        mView.getVpPacketsSuccess(list.getList());

                    }
                }));
    }

    @Override
    public void getNewUserBenfits() {
        mRxDisposable.add(mApiService.getNewUserBoon()
                .subscribe(new AppSubscriber<NewUserBenfit>(mView) {
                    @Override
                    public void next(NewUserBenfit list) {

                        mView.getNewUserBenfits(list);

                    }
                }));
    }

    @Override
    public void getNewUserGoods() {

        mRxDisposable.add(mApiService.new_user_boon_product()
                .subscribe(new AppSubscriber<Product_list>(mView) {
                    @Override
                    public void next(Product_list list) {

                        mView.getNewUserGoodsSuccess(list);

                    }
                }));


    }


}
